<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">


<meta name="google-site-verification" content="E9deYnivN5MuHMuIfiMZZfS0alv-d_0UjcwjBL79lGU" />



<meta name="baidu-site-verification" content="iHYWJxscwD" />










<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />



  <meta name="google-site-verification" content="true" />








  <meta name="baidu-site-verification" content="true" />







  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Python,量化投资,机器学习,数据结构算法,回溯算法," />










<meta name="description" content="开始看书，《你也能看得懂的python算法书》。编程基础，链表等就略读了。哈希算法是通过某种函数映射关系，将复杂的数据，映射成更加易于查找的形式。大多数情况下，哈希算法可以在常数时间内存储和查找这些数据。原理:利用哈希函数存储和查找数据。哈希算法存在冲突的情况，即不同的数据被映射到同一个位置。处理冲突的方法:链地址法。本质上是数组+链表。查找问题，首先想想能不能用哈希算法。搜索问题的本质是试探问题">
<meta property="og:type" content="article">
<meta property="og:title" content="量化投资学习笔记44——基本数据结构算法总结3 回溯算法">
<meta property="og:url" content="https://zwdnet.github.io/2020/04/29/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B044%E2%80%94%E2%80%94%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%AE%97%E6%B3%95%E6%80%BB%E7%BB%933-%E5%9B%9E%E6%BA%AF%E7%AE%97%E6%B3%95/index.html">
<meta property="og:site_name" content="赵瑜敏的口腔医学专业学习博客">
<meta property="og:description" content="开始看书，《你也能看得懂的python算法书》。编程基础，链表等就略读了。哈希算法是通过某种函数映射关系，将复杂的数据，映射成更加易于查找的形式。大多数情况下，哈希算法可以在常数时间内存储和查找这些数据。原理:利用哈希函数存储和查找数据。哈希算法存在冲突的情况，即不同的数据被映射到同一个位置。处理冲突的方法:链地址法。本质上是数组+链表。查找问题，首先想想能不能用哈希算法。搜索问题的本质是试探问题">
<meta property="og:locale">
<meta property="og:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/wx.jpg">
<meta property="article:published_time" content="2020-04-29T05:17:44.000Z">
<meta property="article:modified_time" content="2020-08-30T05:52:04.000Z">
<meta property="article:author" content="赵瑜敏">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="量化投资">
<meta property="article:tag" content="机器学习">
<meta property="article:tag" content="数据结构算法">
<meta property="article:tag" content="回溯算法">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/wx.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://zwdnet.github.io/2020/04/29/量化投资学习笔记44——基本数据结构算法总结3-回溯算法/"/>





  <title>量化投资学习笔记44——基本数据结构算法总结3 回溯算法 | 赵瑜敏的口腔医学专业学习博客</title>
  








<meta name="generator" content="Hexo 5.4.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">赵瑜敏的口腔医学专业学习博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://zwdnet.github.io/2020/04/29/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B044%E2%80%94%E2%80%94%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%AE%97%E6%B3%95%E6%80%BB%E7%BB%933-%E5%9B%9E%E6%BA%AF%E7%AE%97%E6%B3%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/tx.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="赵瑜敏的口腔医学专业学习博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">量化投资学习笔记44——基本数据结构算法总结3 回溯算法</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-04-29T05:17:44+00:00">
                2020-04-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84/" itemprop="url" rel="index">
                    <span itemprop="name">量化投资</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  9
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>开始看书，《你也能看得懂的python算法书》。<br>编程基础，链表等就略读了。<br>哈希算法是通过某种函数映射关系，将复杂的数据，映射成更加易于查找的形式。大多数情况下，哈希算法可以在常数时间内存储和查找这些数据。原理:利用哈希函数存储和查找数据。哈希算法存在冲突的情况，即不同的数据被映射到同一个位置。处理冲突的方法:链地址法。本质上是数组+链表。查找问题，首先想想能不能用哈希算法。<br>搜索问题的本质是试探问题的所有可能选择，按照特定规律和顺序，不断地去搜索答案，直到找到问题的解。有深度优先遍历算法和广度优先遍历算法。<br>回溯算法，采用试错的方法解决问题，当前步骤失败，返回上一个步骤，选择另一个方案继续试错。<br>贪心算法，总是选取局部最优的方案，直到获得最终解决。使用该算法，需要问题具有贪心选择性质，是指应用同一规则f，将原问题变为一个相似的但规模更小的子问题，后面的每一步都是当前看似最佳的选择。另外问题需要具有局部最优解。<br>动态规划算法将待求解问题拆分成一系列相互交叠的子问题，通过递推关系定义各子问题的求解策略，并随时记录子问题的解，最终获得原始问题的解，避免了对交叠子问题的重复求解。<br>在动态规划算法中有三要素，即最优子结构、边界和状态转移函数。最优子结构是指每个阶段的最优状态可以从之前某个阶段的某个或某些状态直接得到；边界是指问题最小子集的解；状态转移函数是指从一个阶段向另一个阶段过渡的具体模式，描述的是两个相邻子问题之间的关系。<br>最短路径算法，有迪可斯特朗算法、Floyd算法、A※算法。<br>用具体例子来看吧。<br>回溯算法（参考: <a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/93530380%EF%BC%89">https://zhuanlan.zhihu.com/p/93530380）</a><br>需要考虑三个问题：路径（已经做出的选择）、选择列表（当前可作的选择）、结束条件（到达决策树底层，无法再做选择的条件）<br>其框架为：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">result = [ ]</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">backtrack</span>(<span class="params">路径, 选择列表</span>):</span></span><br><span class="line">    <span class="keyword">if</span> 满足结束条件:</span><br><span class="line">        result.add(路径)</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    <span class="keyword">for</span> 选择 <span class="keyword">in</span> 选择列表:</span><br><span class="line">        做选择</span><br><span class="line">        backtrack(路径, 选择列表)</span><br><span class="line">        撤销选择</span><br></pre></td></tr></table></figure>
<p>例子：全排列问题。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># coding:utf-8</span></span><br><span class="line"><span class="comment"># 回溯算法</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">permute</span>(<span class="params">nums</span>):</span></span><br><span class="line">    results = []</span><br><span class="line">    track = []</span><br><span class="line">    backtrack(nums, track, results)</span><br><span class="line">    <span class="keyword">return</span> results</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">backtrack</span>(<span class="params">nums, track, results</span>):</span></span><br><span class="line">    <span class="keyword">if</span> <span class="built_in">len</span>(track) == <span class="built_in">len</span>(nums):</span><br><span class="line">        results.append(<span class="built_in">tuple</span>(track))</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">        </span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(nums)):</span><br><span class="line">        <span class="keyword">if</span> nums[i] <span class="keyword">in</span> track:</span><br><span class="line">            <span class="keyword">continue</span></span><br><span class="line">        <span class="comment"># 选择</span></span><br><span class="line">        track.append(nums[i])</span><br><span class="line">        <span class="comment"># 进入下一层决策树</span></span><br><span class="line">        backtrack(nums, track, results)</span><br><span class="line">        <span class="comment"># 取消选择</span></span><br><span class="line">        track.pop()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&quot;__main__&quot;</span>:</span><br><span class="line">    <span class="comment"># 全排列问题</span></span><br><span class="line">    nums = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]</span><br><span class="line">    result = permute(nums)</span><br><span class="line">    print(result)</span><br></pre></td></tr></table></figure>
<p>时间复杂度是O(N!)，因为需要穷举整棵决策树。<br>再来看另一个例子，N皇后问题。<br>跟全排列类似，多了一个判断不合法的位置的函数。<br>参考:<a target="_blank" rel="noopener" href="https://www.geeksforgeeks.org/n-queen-problem-backtracking-3/">https://www.geeksforgeeks.org/n-queen-problem-backtracking-3/</a></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># N皇后问题</span></span><br><span class="line"><span class="function"><span class="keyword">def</span>  <span class="title">solveNQ</span>(<span class="params">N</span>):</span></span><br><span class="line">    board = []</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(N):</span><br><span class="line">        board.append([<span class="number">0</span>]*N)</span><br><span class="line">   </span><br><span class="line">    results = []</span><br><span class="line">    <span class="keyword">global</span> n</span><br><span class="line">    n = <span class="number">0</span></span><br><span class="line">    solveNQUtil(board, <span class="number">0</span>, N, results)</span><br><span class="line">    <span class="comment"># printSolution(results, N)</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">   </span><br><span class="line">   </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">printSolution</span>(<span class="params">board, N</span>):</span></span><br><span class="line">    <span class="keyword">global</span> n</span><br><span class="line">    n += <span class="number">1</span></span><br><span class="line">    print(<span class="string">&quot;\n第&#123;&#125;个结果。\n&quot;</span>.<span class="built_in">format</span>(n))</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(N):</span><br><span class="line">        <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(N):</span><br><span class="line">            print(board[i][j], end = <span class="string">&quot; &quot;</span>)</span><br><span class="line">        print(<span class="string">&quot;\n&quot;</span>)</span><br><span class="line">       </span><br><span class="line">       </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">solveNQUtil</span>(<span class="params">board, col, N, results</span>):</span></span><br><span class="line">    <span class="keyword">if</span> col &gt;= N:</span><br><span class="line">        printSolution(board, N)</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">       </span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(N):</span><br><span class="line">        <span class="keyword">if</span> isSafe(board, i, col, N):</span><br><span class="line">            board[i][col] = <span class="number">1</span></span><br><span class="line">            solveNQUtil(board, col+<span class="number">1</span>, N, results)</span><br><span class="line">            board[i][col] = <span class="number">0</span></span><br><span class="line">   </span><br><span class="line">   </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">isSafe</span>(<span class="params">board, row, col, N</span>):</span></span><br><span class="line">    <span class="comment"># 左侧的列</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(col):</span><br><span class="line">        <span class="keyword">if</span> board[row][i] == <span class="number">1</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">           </span><br><span class="line">    <span class="comment"># 左上对角线</span></span><br><span class="line">    <span class="keyword">for</span> i, j <span class="keyword">in</span> <span class="built_in">zip</span>(<span class="built_in">range</span>(row, -<span class="number">1</span>, -<span class="number">1</span>), <span class="built_in">range</span>(col, -<span class="number">1</span>, -<span class="number">1</span>)):</span><br><span class="line">        <span class="keyword">if</span> board[i][j] == <span class="number">1</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">           </span><br><span class="line">    <span class="comment"># 左下对角线</span></span><br><span class="line">    <span class="keyword">for</span> i, j <span class="keyword">in</span> <span class="built_in">zip</span>(<span class="built_in">range</span>(row, N, <span class="number">1</span>), <span class="built_in">range</span>(col, -<span class="number">1</span>, -<span class="number">1</span>)):</span><br><span class="line">        <span class="keyword">if</span> board[i][j] == <span class="number">1</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">           </span><br><span class="line">    <span class="keyword">return</span> <span class="literal">True</span></span><br></pre></td></tr></table></figure>
<p>再来几个例子，数独问题。<br>9×9的格子，每行，每列以及每3×3格组成的宫里的数字都不相同。<br>参考这里:<a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/99218941">https://zhuanlan.zhihu.com/p/99218941</a></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> datetime <span class="keyword">import</span> datetime</span><br><span class="line"><span class="comment"># 数独的回溯解法</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">sovSudoku</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, board = []</span>):</span></span><br><span class="line">        self._b = board.copy()</span><br><span class="line">        self._t = <span class="number">0</span></span><br><span class="line">        self._n = <span class="number">0</span></span><br><span class="line">       </span><br><span class="line">    <span class="comment"># 主循环，尝试x,y处的解答</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">trysxy</span>(<span class="params">self, x, y</span>):</span></span><br><span class="line">        self._n += <span class="number">1</span></span><br><span class="line">        <span class="keyword">if</span> self._b[x][y] == <span class="number">0</span>:</span><br><span class="line">            pv = self.getPrem(x, y)</span><br><span class="line">            <span class="keyword">for</span> v <span class="keyword">in</span> pv:</span><br><span class="line">                self._t += <span class="number">1</span></span><br><span class="line">                <span class="keyword">if</span> self.checkNotSame(x, y, v):</span><br><span class="line">                    self._b[x][y] = v</span><br><span class="line">                    nx, ny = self.getNext(x, y)</span><br><span class="line">                    <span class="keyword">if</span> nx == -<span class="number">1</span>:</span><br><span class="line">                        <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">                    <span class="keyword">else</span>:</span><br><span class="line">                        _end = self.trysxy(nx, ny)</span><br><span class="line">                        <span class="keyword">if</span> <span class="keyword">not</span> _end:</span><br><span class="line">                            self._b[x][y] = <span class="number">0</span></span><br><span class="line">                        <span class="keyword">else</span>:</span><br><span class="line">                            <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">           </span><br><span class="line">    <span class="comment"># 得到x, y处可以填的值</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">getPrem</span>(<span class="params">self, x, y</span>):</span></span><br><span class="line">        prem = []</span><br><span class="line">        rows = <span class="built_in">list</span>(self._b[x])</span><br><span class="line">        rows.extend([self._b[i][y] <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">9</span>)])</span><br><span class="line">        cols = <span class="built_in">set</span>(rows)</span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, <span class="number">10</span>):</span><br><span class="line">            <span class="keyword">if</span> i <span class="keyword">not</span> <span class="keyword">in</span> cols:</span><br><span class="line">                prem.append(i)</span><br><span class="line">        <span class="keyword">return</span> prem</span><br><span class="line">       </span><br><span class="line">    <span class="comment"># 检查每行每列和每个宫内是否有与b(x, y)相同的数字</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">checkNotSame</span>(<span class="params">self, x, y, val</span>):</span></span><br><span class="line">        <span class="comment"># 第x行</span></span><br><span class="line">        <span class="keyword">for</span> row_item <span class="keyword">in</span> self._b[x]:</span><br><span class="line">            <span class="keyword">if</span> row_item == val:</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">        <span class="comment"># 第y列</span></span><br><span class="line">        <span class="keyword">for</span> rows <span class="keyword">in</span> self._b:</span><br><span class="line">            <span class="keyword">if</span> rows[y] == val:</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">        ax = x//<span class="number">3</span>*<span class="number">3</span></span><br><span class="line">        ab = y//<span class="number">3</span>*<span class="number">3</span></span><br><span class="line">        <span class="keyword">for</span> r <span class="keyword">in</span> <span class="built_in">range</span>(ax, ax+<span class="number">3</span>):</span><br><span class="line">            <span class="keyword">for</span> c <span class="keyword">in</span> <span class="built_in">range</span>(ab, ab+<span class="number">3</span>):</span><br><span class="line">                <span class="keyword">if</span> self._b[r][c] == val:</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">        <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">       </span><br><span class="line">    <span class="comment"># 得到下一个未填项</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">getNext</span>(<span class="params">self, x, y</span>):</span></span><br><span class="line">        <span class="keyword">for</span> ny <span class="keyword">in</span> <span class="built_in">range</span>(y+<span class="number">1</span>, <span class="number">9</span>):</span><br><span class="line">            <span class="keyword">if</span> self._b[x][ny] == <span class="number">0</span>:</span><br><span class="line">                <span class="keyword">return</span> (x, ny)</span><br><span class="line">        <span class="keyword">for</span> row <span class="keyword">in</span> <span class="built_in">range</span>(x+<span class="number">1</span>, <span class="number">9</span>):</span><br><span class="line">            <span class="keyword">for</span> ny <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, <span class="number">9</span>):</span><br><span class="line">                <span class="keyword">if</span> self._b[row][ny] == <span class="number">0</span>:</span><br><span class="line">                    <span class="keyword">return</span> (row, ny)</span><br><span class="line">        <span class="keyword">return</span> (-<span class="number">1</span>, -<span class="number">1</span>)</span><br><span class="line">       </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">solve</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="keyword">if</span> self._b[<span class="number">0</span>][<span class="number">0</span>] == <span class="number">0</span>:</span><br><span class="line">            self.trysxy(<span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            x, y = self.getNext(<span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">            self.trysxy(x, y)</span><br><span class="line">           </span><br><span class="line">            <span class="function"><span class="keyword">def</span> <span class="title">updateSudo</span>(<span class="params">self, cb</span>):</span></span><br><span class="line">                <span class="keyword">if</span> <span class="built_in">len</span>(cb) == <span class="number">9</span> <span class="keyword">and</span> <span class="built_in">len</span>(cb[<span class="number">0</span>] == <span class="number">9</span>):</span><br><span class="line">                    self._b = cb</span><br><span class="line">                <span class="keyword">else</span>:</span><br><span class="line">                    print(<span class="string">&quot;错误结果&quot;</span>, <span class="built_in">len</span>(cb), <span class="built_in">len</span>(cb[<span class="number">0</span>]))</span><br><span class="line">                  </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__str__</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">&#x27;&#123;0&#125;&#123;1&#125;&#123;2&#125;&#x27;</span>.<span class="built_in">format</span>(<span class="string">&#x27;[&#x27;</span>,<span class="string">&#x27;,\n&#x27;</span>.join([<span class="built_in">str</span>(i) <span class="keyword">for</span> i <span class="keyword">in</span> self._b]),<span class="string">&#x27;]&#x27;</span>)</span><br><span class="line">       </span><br><span class="line">    <span class="comment"># 获得回溯次数</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">getTNum</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="keyword">return</span> self._n</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&quot;__main__&quot;</span>:</span><br><span class="line">    <span class="comment"># 数独问题</span></span><br><span class="line">    s1 = [</span><br><span class="line">            [<span class="number">8</span>,<span class="number">0</span>,<span class="number">0</span>, <span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>, <span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>],</span><br><span class="line">            [<span class="number">0</span>,<span class="number">0</span>,<span class="number">3</span>, <span class="number">6</span>,<span class="number">0</span>,<span class="number">0</span>, <span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>],</span><br><span class="line">            [<span class="number">0</span>,<span class="number">7</span>,<span class="number">0</span>, <span class="number">0</span>,<span class="number">9</span>,<span class="number">0</span>, <span class="number">2</span>,<span class="number">0</span>,<span class="number">0</span>],</span><br><span class="line">            [<span class="number">0</span>,<span class="number">5</span>,<span class="number">0</span>, <span class="number">0</span>,<span class="number">0</span>,<span class="number">7</span>, <span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>],</span><br><span class="line">            [<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>, <span class="number">0</span>,<span class="number">4</span>,<span class="number">5</span>, <span class="number">7</span>,<span class="number">0</span>,<span class="number">0</span>],</span><br><span class="line">            [<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>, <span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>, <span class="number">0</span>,<span class="number">3</span>,<span class="number">0</span>],</span><br><span class="line">            [<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>, <span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>, <span class="number">0</span>,<span class="number">6</span>,<span class="number">8</span>],</span><br><span class="line">            [<span class="number">0</span>,<span class="number">0</span>,<span class="number">8</span>, <span class="number">5</span>,<span class="number">0</span>,<span class="number">0</span>, <span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>],</span><br><span class="line">            [<span class="number">0</span>,<span class="number">9</span>,<span class="number">0</span>, <span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>, <span class="number">4</span>,<span class="number">0</span>,<span class="number">0</span>]</span><br><span class="line">        ]</span><br><span class="line">    begin = datetime.now()</span><br><span class="line">    ss = sovSudoku(s1)</span><br><span class="line">    ss.solve()</span><br><span class="line">    print(datetime.now() - begin)</span><br><span class="line">    print(ss)</span><br><span class="line">    print(ss.getTNum())</span><br><span class="line">   </span><br><span class="line">    m = [</span><br><span class="line">        [<span class="number">6</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">7</span>, <span class="number">0</span>, <span class="number">8</span>],</span><br><span class="line">        [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">8</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">2</span>, <span class="number">0</span>, <span class="number">0</span>],</span><br><span class="line">        [<span class="number">2</span>, <span class="number">3</span>, <span class="number">8</span>, <span class="number">0</span>, <span class="number">5</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>],</span><br><span class="line">        [<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">9</span>, <span class="number">2</span>],</span><br><span class="line">        [<span class="number">0</span>, <span class="number">0</span>, <span class="number">4</span>, <span class="number">3</span>, <span class="number">0</span>, <span class="number">8</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">0</span>],</span><br><span class="line">        [<span class="number">3</span>, <span class="number">7</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>],</span><br><span class="line">        [<span class="number">0</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">0</span>, <span class="number">7</span>, <span class="number">0</span>, <span class="number">5</span>, <span class="number">2</span>, <span class="number">6</span>],</span><br><span class="line">        [<span class="number">0</span>, <span class="number">0</span>, <span class="number">2</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>],</span><br><span class="line">        [<span class="number">9</span>, <span class="number">0</span>, <span class="number">7</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">4</span>]</span><br><span class="line">    ]</span><br><span class="line">    begin = datetime.now()</span><br><span class="line">    ss = sovSudoku(m</span><br><span class="line">    )</span><br><span class="line">    ss.solve()</span><br><span class="line">    print(datetime.now() - begin)</span><br><span class="line">    print(ss)</span><br><span class="line">    print(ss.getTNum())</span><br></pre></td></tr></table></figure>
<p>现在来看另一个问题，0-1背包问题。<br>参考这里:<a target="_blank" rel="noopener" href="https://www.cnblogs.com/xiaomangxie/p/10208441.html">https://www.cnblogs.com/xiaomangxie/p/10208441.html</a><br>有N件物品和一个容量为V的背包。第i件物品的价格（即体积，下同）是w[i]，价值是c[i]。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量，且价值总和最大。<br>回溯法解决看这里:<a target="_blank" rel="noopener" href="http://www.jeepxie.net/article/273672.html">http://www.jeepxie.net/article/273672.html</a></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 背包问题</span></span><br><span class="line">bestV = <span class="number">0</span></span><br><span class="line">curW = <span class="number">0</span></span><br><span class="line">curV = <span class="number">0</span></span><br><span class="line">bestx = <span class="literal">None</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">backtrack</span>(<span class="params">i</span>):</span></span><br><span class="line">    <span class="keyword">global</span> bestV,curW,curV,x,bestx</span><br><span class="line">    <span class="keyword">if</span> i &gt;= n:</span><br><span class="line">        <span class="keyword">if</span> bestV &lt; curV:</span><br><span class="line">            bestV = curV</span><br><span class="line">            bestx = x[:]</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        <span class="keyword">if</span> curW + w[i] &lt;= c:</span><br><span class="line">            x[i] = <span class="literal">True</span></span><br><span class="line">            curW += w[i]</span><br><span class="line">            curV += v[i]</span><br><span class="line">            backtrack(i+<span class="number">1</span>)</span><br><span class="line">            curW -= w[i]</span><br><span class="line">            curV -= v[i]</span><br><span class="line">        x[i] = <span class="literal">False</span></span><br><span class="line">        backtrack(i+<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">n=<span class="number">5</span></span><br><span class="line">c=<span class="number">10</span></span><br><span class="line">w=[<span class="number">2</span>,<span class="number">2</span>,<span class="number">6</span>,<span class="number">5</span>,<span class="number">4</span>]</span><br><span class="line">v=[<span class="number">6</span>,<span class="number">3</span>,<span class="number">5</span>,<span class="number">4</span>,<span class="number">6</span>]</span><br><span class="line">x=[<span class="literal">False</span> <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(n)]</span><br><span class="line">backtrack(<span class="number">0</span>)</span><br><span class="line">print(bestV)</span><br><span class="line">print(bestx)</span><br></pre></td></tr></table></figure>
<p>本章代码: <a target="_blank" rel="noopener" href="https://github.com/zwdnet/MyQuant/blob/master/43/backtrace.py">https://github.com/zwdnet/MyQuant/blob/master/43/backtrace.py</a></p>
<p>我发文章的三个地方，欢迎大家在朋友圈等地方分享，欢迎点“在看”。<br>我的个人博客地址：<a href="https://zwdnet.github.io/">https://zwdnet.github.io</a><br>我的知乎文章地址： <a target="_blank" rel="noopener" href="https://www.zhihu.com/people/zhao-you-min/posts">https://www.zhihu.com/people/zhao-you-min/posts</a><br>我的微信个人订阅号：赵瑜敏的口腔医学学习园地</p>
<p><img src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/wx.jpg"></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>欢迎打赏！感谢支持！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/mm_facetoface_collect_qrcode_1542944836634.png" alt=" 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/1542944857770.jpg" alt=" 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Python/" rel="tag"># Python</a>
          
            <a href="/tags/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84/" rel="tag"># 量化投资</a>
          
            <a href="/tags/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/" rel="tag"># 机器学习</a>
          
            <a href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%AE%97%E6%B3%95/" rel="tag"># 数据结构算法</a>
          
            <a href="/tags/%E5%9B%9E%E6%BA%AF%E7%AE%97%E6%B3%95/" rel="tag"># 回溯算法</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/04/29/%E7%89%99%E9%AB%93%E7%97%85%E6%80%BB%E7%BB%9316%E2%80%94%E2%80%94%E6%A0%B9%E7%AE%A1%E6%B2%BB%E7%96%97%E5%90%8E%E7%9A%84%E4%BF%AE%E5%A4%8D%E6%96%B9%E6%A1%88/" rel="next" title="牙髓病总结16——根管治疗后的修复方案">
                <i class="fa fa-chevron-left"></i> 牙髓病总结16——根管治疗后的修复方案
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/04/30/%E9%87%8F%E5%8C%96%E6%8A%95%E8%B5%84%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B045%E2%80%94%E2%80%94%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%AE%97%E6%B3%95%E6%80%BB%E7%BB%934-%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/" rel="prev" title="量化投资学习笔记45——基本数据结构算法总结4 动态规划">
                量化投资学习笔记45——基本数据结构算法总结4 动态规划 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC80MTA2Mi8xNzU4Nw=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="https://zymblog-1258069789.cos.ap-chengdu.myqcloud.com/other/tx.jpg"
                alt="" />
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%20%7C%7C%20archive">
              
                  <span class="site-state-item-count">452</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">29</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">544</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">本站版权归赵瑜敏所有，如欲转载请与本人联系。</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">1225.8k</span>
  
</div>









<div>
  <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1275447216'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s11.cnzz.com/z_stat.php%3Fid%3D1275447216%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));</script>
</div>

        







  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1275447216&web_id=1275447216" language="JavaScript"></script>
  </div>



        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  





  

  

  

  
  

  

  

  

  
</body>
</html>
